<template>
  <div class="room-list-setting">
    <Breadcrumb :pathContent="content" />
    <div class="room-list-content">
      <el-form>
        <div class="room-header">
          <el-form-item>
            <el-cascader :options="cities" :props="{ value: 'cityid', label: 'city', children: 'citiess' }" @change="handleCascader" filterable change-on-select>
            </el-cascader>
            <div class="search-input">
              <div class="input-with-select el-input el-input-group el-input-group--append">
                <input autocomplete="off" placeholder="请输入酒店名/酒店ID" type="text" rows="2" validateevent="true" class="el-input__inner" @keyup.enter="searchHotel" v-model="searchKey">
              </div>
              <el-button type="primary" @click="searchHotel" class="searchHotel">
                <i class="el-icon-search"></i>
              </el-button>
              <el-button type="text" size="small" style="float: right;" @click="show">{{listTitle}}</el-button>
            </div>
          </el-form-item>
          <div class="carousel" v-show="carouselShow">
            <el-form-item>
              <el-carousel trigger="click" height="200px" :autoplay="false" arrow="never" indicator-position="none" ref="hotelList">
                <el-carousel-item :key="item">
                  <div class="item" v-for="(value, index) in HoteltableData" :class="{'item-active': index === 0}" @click="hotelInformation($event, index, value)" ref="itemList" :key="index">{{value.name}}</div>
                </el-carousel-item>
              </el-carousel>
            </el-form-item>
            <div class="pagination">
              <div class="pagination-left">
                <p>共搜索到{{HotelTotal}}家酒店</p>
              </div>
              <div class="pagination-right">
                <el-pagination @size-change="handleHotelSizeChange" @current-change="handleHotelCurrentChange" :current-page="HotelCurrentPage" :page-sizes="[10, 20, 30, 40]" :page-size="HotelPageSize" layout="total, prev, pager, next, jumper" :total="HotelTotal">
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
        <div class="suppliers-infromation">
          <el-form-item style="margin-bottom: 10px;">
            <div class="title">{{HotelName}}</div>
            <div class="suppliers">
              <el-select v-model="suppliersValue" placeholder="请选择供应商" @change="supplierChange">
                <div class="select" v-for="(items,index) in suppliers" :key="index">
                  <el-option :label="items.name" :value="items.name"></el-option>
                </div>
              </el-select>
            </div>
            <div class="call">联系电话: 0731-89589589</div>
          </el-form-item>
          <el-form-item style="margin-bottom: 20px;">
            <label style="font-size: 12px;">在售:</label>
            <label style="font-size: 12px; color: #45a2ff;">美团</label>
          </el-form-item>
          <div class="tab-pane">
            <el-form-item style="margin: 0;">
              <el-tabs v-model="currentName" type="card" @tab-click="handleClick">
                <el-tab-pane label="房价/房态管理" name="first">
                  <PropertyManagement :dataTable="InventoryData" />
                </el-tab-pane>
                <el-tab-pane label="库存管理" name="second">
                  <InventoryManagement :dataTable="InventoryData" />
                </el-tab-pane>
              </el-tabs>
            </el-form-item>
          </div>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getSaleHotelNames, getProductQuery, getSuppliersNameList } from '../../../public/js/saleRoom'
const Breadcrumb = () => import('@/components/common/Breadcrumb')
const InventoryManagement = () => import('@/components/room/room_list/InventoryManagement')
const PropertyManagement = () => import('@/components/room/room_list/PropertyManagement')
const cityData = require('@/data/cities.json')
export default {
  name: 'Staff',
  data () {
    return {
      listTitle: '收起酒店列表',
      currentName: 'first',
      carouselShow: true,
      cities: cityData.provincesEntities,
      suppliersValue: '',
      item: '',
      HotelTotal: 0,
      HotelName: '',
      RoomTotal: 0,
      props: {
        value: 'label',
        children: 'cities'
      },
      content: {
        firstTitle: '房型',
        secondTitle: '房型列表',
        type: 'close'
      },
      showDepartment: false,
      ruleForm: {
        name: '',
        superior: ''
      },
      suppliers: [],
      HoteltableData: [],
      HotelCurrentPage: 1,
      HotelPageSize: 16,
      RoomValue: {
        startDate: window.commo.time(),
        pageSize: 10,
        pageNum: 1,
        limitDays: 7
      },
      saleHotelId: null,
      supplierId: '',
      searchKey: '',
      city: null,
      timeState: 1,
      hotelId: 0,
      windowStyle: false,
      InventoryData: [],
      newInventoryData: []
    }
  },
  created () {
    this.getSalseHotelNamesAll()
    console.log(this.newInventoryData)
  },
  mounted () {
    window.bus.$on('starDate', res => {
      this.RoomValue.startDate = res
    })
    window.bus.$on('limitDays', res => {
      this.RoomValue.limitDays = res
    })
    window.bus.$on('hotelId', res => {
      this.hotelId = res
    })
  },
  watch: {
    carouselShow (val) {
      val ? this.listTitle = '收起酒店列表' : this.listTitle = '展开酒店列表'
      this.windowStyle = val
      this.$refs.hotelList.$children[0].$el.style.display = 'block'
      //   val ? window.bus.$emit('WindowStyle', val) : window.bus.$emit('WindowStyle', val)
    },
    newInventoryData: {
      handler (val) {
        this.InventoryData = val
      },
      deep: true
    }
  },
  methods: {
    getSalseHotelNamesAll () {
      getSaleHotelNames(this).then(res => {
        this.HoteltableData = res.data.list
        this.HotelTotal = res.data.total
        if (res.data.list) {
          if (res.data.list.length > 0) {
            this.HotelName = res.data.list[0].name
            this.requestHotelData(res.data.list[0].id)
          }
        }
      })
    },
    searchHotel () {
      this.getSalseHotelNamesAll()
    },
    handleCascader (val) {
      this.city = parseInt(val[val.length - 1])
      this.getSalseHotelNamesAll()
    },
    sendDatas (data) {
      // console.log('data', data)
      // window.bus.$emit('InventoryData', data.staticRoomEntities)
      this.InventoryData = data.staticRoomEntities
      console.log('this.InventoryData', data)
      window.bus.$emit('SaleInformation', { saleHotelId: this.RoomValue.saleHotelId, supplierId: this.RoomValue.supplierId, total: data.total, windowStyle: this.windowStyle, limitDays: this.RoomValue.limitDays })
    },
    supplierChange (val) {
      new Promise((resolve, reject) => {
        resolve(this.suppliers.forEach((key, index) => {
          if (key.name === val) this.RoomValue.supplierId = key.id
        }))
      }).then(() => {
        getProductQuery(this.RoomValue).then(res => {
          if (res.data.errCode === 0) {
            window.bus.$emit('pricePermissions', res.data.isLowerLevel)
            this.sendDatas(res.data)
          }
        })
      })
    },
    requestHotelData (hotelid) {
      this.saleHotelId = hotelid
      this.RoomValue.saleHotelId = hotelid
      getSuppliersNameList(this).then(res => {
        return res.data
      }).then(res => {
        if (res.supplierNames[0].id) this.RoomValue.supplierId = res.supplierNames[0].id
        this.suppliers = res.supplierNames
        this.suppliersValue = res.supplierNames[0].name
        getProductQuery(this.RoomValue).then(res => {
          if (res.data.errCode === 0) {
            window.bus.$emit('pricePermissions', res.data.isLowerLevel)
            this.sendDatas(res.data)
          }
        })
      })
    },
    hotelInformation (event, index, value) {
      this.$refs.itemList.forEach(item => {
        item.classList.remove('item-active')
      })
      event.target.classList.add('item-active')
      this.requestHotelData(this.HoteltableData[index].id)
      this.HotelName = value.name
    },
    show () {
      this.carouselShow ? this.carouselShow = false : this.carouselShow = true
    },
    handleClick () {
      getProductQuery(this.RoomValue).then(res => {
        if (res.data.errCode === 0) {
          window.bus.$emit('pricePermissions', res.data.isLowerLevel)
          this.sendDatas(res.data)
        }
      })
    },
    handleHotelSizeChange (val) {
      this.HotelPageSize = val
      this.getSalseHotelNamesAll()
    },
    handleHotelCurrentChange (val) {
      this.HotelCurrentPage = val
      this.getSalseHotelNamesAll()
    }
  },
  components: {
    Breadcrumb,
    InventoryManagement,
    PropertyManagement
  }
}
</script>
<style lang="scss">
.room-list-content {
  background-color: white;
  padding: 20px;
  position: relative;
  font-size: 12px;
  color: #415161;
  .el-table {
    /*调整th与td的宽度占比*/
    .el-table__body,
    .el-table__header {
      width: 100% !important;
    }
  }
  // 头部轮播
  .el-carousel {
    z-index: 1;
    ul {
      li:hover {
        color: #45a2ff;
        cursor: pointer;
      }
    }
  }
  .el-form {
    .el-form-item {
      .el-form-item__content {
        line-height: 2;
        .el-cascader {
          float: left;
          margin-right: 20px;
        }
        .el-input {
          float: left;
          width: 400px;
          input {
            height: 30px;
            line-height: 30px;
          }
        }
        /*搜索input样式*/
        .el-input {
          width: 400px;
          input {
            height: 34px;
            line-height: 34px;
          }
          .el-input-group__append {
            padding: 0 14px;
            .el-button {
              margin: -14px;
            }
            button {
              padding: 8px 9px;
            }
          }
          .el-input-group__append:hover {
            background-color: #45a2ff;
            color: #fff;
            border-radius: 0 4px 4px 0;
          }
        }
        /*搜索input样式结束*/
        .el-pagination {
          text-align: right;
          .el-pagination__jump {
            .el-input {
              float: none !important;
              width: 50px !important;
            }
          }
          .el-input {
            width: 100px;
          }
        }
      }
    }
  }
}
.expand-trigger div {
  height: 50px !important;
}

.room-list-content .el-form .el-form-item .el-form-item__content {
  text-align: left;
  .el-select {
    width: 200px;
    margin-right: 20px;
    float: left;
  }
}
.room-list-content .el-form .el-form-item .el-form-item__content .el-input {
  width: 200px;
}

.room-list-content .el-form .el-form-item .el-form-item__content {
  .search-input {
    overflow: hidden;
    .input-with-select {
      width: 400px;
    }
    .searchHotel {
      line-height: 32px;
      padding: 0 21px;
      margin-left: 15px;
    }
  }
}

.room-list-content .el-form .el-form-item .el-form-item__content .el-cascader {
  line-height: 1.8;
}
.carousel {
  background-color: rgb(246, 246, 246);
}
.carousel {
  padding: 17px;
  margin-bottom: 20px;
  position: relative;
  .item {
    width: 25%;
    overflow: hidden;
    float: left;
    font-size: 12px;
    height: 21%;
    text-align: center;
    line-height: 3.5;
    cursor: pointer;
  }
  .item:hover {
    color: #45a2ff;
  }
}
.pagination {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  z-index: 2;
  .pagination-left,
  .pagination-right {
    width: 50%;
    height: 40px;
  }
  .pagination-left {
    float: left;
    text-align: left;
    p {
      color: rgb(207, 215, 221);
      margin-left: 30px;
      line-height: 40px;
    }
  }
  .pagination-right {
    text-align: right;
    float: right;
    .el-pagination {
      line-height: 1;
      margin-right: 20px;
      .el-pagination__jump {
        margin-left: 0;
      }
      .el-pager {
        width: auto;
        float: none;
        li {
          width: 28px;
          height: 28px;
          line-height: 28px;
        }
      }
    }
  }
}
.suppliers-infromation {
  font-size: 12px;
  .title,
  .suppliers {
    float: left;
  }
  .title {
    margin-right: 30px;
    line-height: 34px;
    font-size: 12px;
  }
  .call {
    float: right;
    font-size: 12px;
  }
}
.tab-pane {
  .el-tabs--card > .el-tabs__header .el-tabs__nav {
    border: none;
  }
  .el-tabs--card > .el-tabs__header {
    border-bottom: 1px solid #45a2ff;
  }
  .el-tabs--card > .el-tabs__header .el-tabs__item {
    margin-right: 5px;
    border-top: 1px solid #45a2ff;
    border-left: 1px solid #45a2ff;
    border-right: 1px solid #45a2ff;
    border-radius: 3px;
    border-bottom: none;
    color: #45a2ff;
  }
  .is-active {
    background-color: #45a2ff;
    color: white !important;
  }
  .el-tabs--bottom .el-tabs__item:nth-child(2),
  .el-tabs--top .el-tabs__item:nth-child(2) {
    border-top: 1px solid #45a2ff;
    border-left: 1px solid #45a2ff;
    border-right: 1px solid #45a2ff;
    border-radius: 3px;
    color: #45a2ff;
  }
}
.item-active {
  color: #45a2ff;
}
</style>
